<?php

class Partida {
	public $id;
	public $pektis1;
	public $pektis2;
	public $ekinisi;
	public $telos;
	public $nikitis;

	public function __construct($row = NULL) {
		$this->id = NULL;
		$this->pektis1 = NULL;
		$this->pektis2 = NULL;
		$this->ekinisi = NULL;
		$this->telos = NULL;
		$this->nikitis = NULL;

		if (isset($row)) {
			if (is_array($row)) {
				$this->id = $row['id'];
				$this->pektis1 = $row['pektis1'];
				$this->pektis2 = $row['pektis2'];
				$this->ekinisi = $row['ekinisi'];
				$this->telos = $row['telos'];
				$this->nikitis = $row['nikitis'];
			}
			else {
				$row = explode("\t", $row);
				if (count($row) != 6) {
					return;
				}

				$nf = 0;
				$this->id = $row[$nf++];
				$this->pektis1 = $row[$nf] ? $row[$nf] : NULL;
				$nf++;
				$this->pektis2 = $row[$nf] ? $row[$nf] : NULL;
				$nf++;
				$this->ekinisi = $row[$nf++];
				$this->telos = $row[$nf] ? $row[$nf] : NULL;
				$nf++;
				$this->nikitis = $row[$nf] ? $row[$nf] : NULL;
				$nf++;
			}
					
		}
	}

	public function arxio($fp) {
		Globals::put_line($fp, $this->id . "\t" . $this->pektis1 . "\t" .
			$this->pektis2 . "\t" . $this->ekinisi . "\t" .
			$this->telos . "\t" . $this->nikitis);
	}

	public function json() {
		print "{k:" . $this->id;
		if (isset($this->pektis1)) {
			print  ",p1:'" . Globals::json_safe($this->pektis1) . "'";
		}
		if (isset($this->pektis2)) {
			print  ",p2:'" . Globals::json_safe($this->pektis2) . "'";
		}
		if (isset($this->nikitis)) {
			print  ",n:" . $this->nikitis;
		}
		print "}";
	}
}

?>
